import zipfile
import os
import sys  # 导入 sys 模块

def extract_zip_with_password(zip_file_path, password):
    try:
        if not os.path.exists(zip_file_path):
            print(f"文件不存在: {zip_file_path}")
            sys.exit()  # 终止程序
        with zipfile.ZipFile(zip_file_path, 'r') as zip_ref:
            zip_ref.extractall(pwd=password.encode())
        print(f"成功解压，密码是: {password}")
        return True
    except Exception as e:
        print("密码错误: ")
         

def brute_force_zip(zip_file_path):
   
    for i in range(1000000):  # 假设密码是六位数字
       
        password = str(i).zfill(6)  # 将数字转换为六位字符串，前面补零
        print(f"尝试密码: {password}")  # 输出当前尝试的密码
        if extract_zip_with_password(zip_file_path, password):
            print(f"尝试次数: {attempt_count}")  # 成功解压后输出尝试次数
            break
        
        
# 获取用户输入的ZIP文件路径
zip_file_path = input("请输入ZIP文件的路径: ")

# 执行暴力破解过程
brute_force_zip(zip_file_path)

